package com.baizhi.zjs.BookTest;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.swing.JSpinner.ListEditor;

import oracle.net.aso.b;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.baizhi.zjs.dao.BookDAO;
import com.baizhi.zjs.entity.BookEntity;
import com.baizhi.zjs.entity.CategoryEntity;
import com.baizhi.zjs.service.BookService;
import com.baizhi.zjs.service.BookServiceImpl;
import com.baizhi.zjs.util.MybatisUtil;
import com.baizhi.zjs.util.UUIDUtil;

public class book {
@Test
public void addbookDAO() throws Exception{
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	/*//创建java日期转换对象
	  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	//字符串转换日期对象
	String aa="2009-09-03";*/
	
	//Date date=format.parse(aa);
	
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	Date  date=format.parse("2009-04-03");
	String uuid = UUIDUtil.getUuid();
/*	(
			  uuid, ,"一个陌生女人的来信","玄幻小说",56.50, 52.50,300,"薛莹莹","人民出版社",date, "第五次",date,"第六次","123123","3开","原浆纸",
			 "精装","23324","12323345","back/images/1900594623-1_l_2.jpg","qqwe","qweqwe","qweqwre","ertgtb","erteryghbf",0,date
			  )*/
	BookEntity bookEntity = new BookEntity  (uuid, "一个陌生女人的来信","玄幻小说",56.50, 52.50,300,"薛莹莹","人民出版社",date, "第五次",date,"第六次","123123","3开","原浆纸",
			 "精装","23324","12323345","back/images/1900594623-1_l_2.jpg","qqwe","qweqwe","qweqwre","ertgtb","erteryghbf",0,date);
	System.out.println(bookEntity);
	//dao.addBook(bookEntity);
	MybatisUtil.commit(sqlSession);
	MybatisUtil.close(sqlSession);
	
}
//添加图书的测试
@Test
public void addBookService() throws Exception{
	BookServiceImpl impl = new BookServiceImpl();
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	Date  date=format.parse("2009-04-03");
	String uuid = UUIDUtil.getUuid();
	BookEntity book = new BookEntity (uuid, "第1个陌生女人的来信","玄幻小说",56.50, 52.50,300,"薛莹莹","人民出版社",date, "第五次",date,"第六次","123123","3开","原浆纸",
			 "精装","23324","12323345","/back/images/1900594623-1_l_2.jpg","qqwe","qweqwe","qweqwre","ertgtb","erteryghbf",0,date);
	impl.addBook(book);
}
//查询所有图书DAO
@Test
public void showAllBokDAO(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	List<BookEntity> list = dao.showAllBook();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
//查询所有图书的service层
@Test
public void showBookService(){
	BookService Impl = new BookServiceImpl();
	List<BookEntity> list = Impl.showAllBook();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
	
}
//删除图书DAO
@Test
public  void deleteBookDAO(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	dao.delectBook("255a14dbe07a411b8f9c2c8cfed6cbad");
	MybatisUtil.commit(sqlSession);
	MybatisUtil.close(sqlSession);
}
@Test
//查询一条图书信息
public void  shoeOneBookDAO(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	BookEntity book = dao.showOneBook("101");
	System.out.println(book);
	MybatisUtil.close(sqlSession);
}
@Test
//查询一条图书信息
public void ShowOneBook(){
	BookServiceImpl impl = new BookServiceImpl();
	BookEntity entity = impl.shoeOneBook("101");
	System.out.println(entity);
}
@Test
public void update(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	BookEntity book = new BookEntity ("101", "第十个陌生女人的来信","玄幻小说",56.50, 52.50,300,"薛莹莹","人民出版社",null, "第五次",null,"第六次","123123","3开","原浆纸",
			 "精装","23324","12323345","/back/images/1900594623-1_l_2.jpg","qqwe","qweqwe","qweqwre","ertgtb","erteryghbf",0,null);
	dao.updateBook(book);
	MybatisUtil.commit(sqlSession);
	MybatisUtil.close(sqlSession);
}
//修改图书的service测试
@Test
public void updateOneB(){
	BookServiceImpl impl = new BookServiceImpl();
	BookEntity book = new BookEntity ("102", "一群陌生女人的来信","玄幻小说",56.50, 52.50,300,"薛莹莹","人民出版社",null, "第五次",null,"第六次","123123","3开","原浆纸",
			 "精装","23324","12323345","/back/images/1900594623-1_l_2.jpg","qqwe","qweqwe","qweqwre","ertgtb","erteryghbf",0,null);
	impl.updateOneBook(book);
}
//模糊查询
@Test 
public void queryLike(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	BookEntity book = new BookEntity();
	book.setWritwer("莹");
	List<BookEntity> list = dao.likeBook(book);
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
@Test
public void likeBook(){
	BookService impl = new BookServiceImpl();
	BookEntity book = new BookEntity();
	book.setWritwer("莹");
	List<BookEntity> list = impl.likeBook(book);
	System.out.println(list);
}
//前台热销图书
@Test
public void ww1(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	List<BookEntity> list = dao.fShowHotBook();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
		
	}
}
//前台最新上架DAO
@Test
public void newBook(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	List<BookEntity> list = dao.fShowNewBook();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
@Test
//前台最新上架service
public void newBookS(){
	BookServiceImpl impl = new BookServiceImpl();
	List<BookEntity> list = impl.fShowNewBook();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
@Test
//前台新书热卖
public void newHot(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	List<BookEntity> list = dao.fShowNewHotBook();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
//前台编辑推荐
@Test
public void fShowCompile(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	List<BookEntity> list = dao.fShowCompile();
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
//前台测试查询一级类别下的所有图书
@Test
public void queryOneCeateBook(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	List<BookEntity> list = dao.queryOneCeateBook("1","4",2,4);
	for (BookEntity bookEntity : list) {
		System.out.println(bookEntity);
	}
}
// "1563704808bf498f9682d22dc0a9d25c"
@Test
public void queryOneCeateBookS(){
	BookServiceImpl impl = new BookServiceImpl();
	List<BookEntity> ca = impl.queryOneCeateBook("1","4",1,2);
	System.out.println(ca);
	for (BookEntity iterab : ca) {
		System.out.println(iterab);
	}
	
}
//前台查询图书的数量，写分页查询用
@Test
public void queryByCount(){
	SqlSession sqlSession = MybatisUtil.getSqlSession();
	BookDAO dao = sqlSession.getMapper(BookDAO.class);
	Integer count = dao.queryByCount("6", "1563704808bf498f9682d22dc0a9d25c");
	System.out.println(count);
}
}
